﻿//using GalaSoft.MvvmLight;
//using GalaSoft.MvvmLight.Command;
using System;
using TimedTask.Core;
using TimedTask.Models;
using TimedTask.Tools;

namespace TimedTask.ViewModel
{
    public class MainViewModel : BaseViewModel
    {
        private Tools.Calendar calender = new Tools.Calendar(DateTime.Now);

        /// <summary>
        /// 初始化 MainViewModel
        /// </summary>
        public MainViewModel()
        {
            Loading();
            //网络监控
            NetworkMonitorSM sm = new NetworkMonitorSM();
            sm.callback += (info) =>
            {
                MonitorInfo moinfo = (MonitorInfo)info;
                moinfo.ToString();
                this.NetUpSpeed = moinfo.UpSpeed;
                this.NetDownSpeed = moinfo.DownSpeed;
            };
            sm.StartMonitor();

        }
        #region 属性
        private WeatherInfo _WeatherInfos;
        private string _NetUpSpeed;
        private string _NetDownSpeed;

        /// <summary> 程序版本 </summary>
        public string Verson { get; set; }

        /// <summary> 天气信息 </summary>
        public WeatherInfo WeatherInfos
        {
            get { return _WeatherInfos; }
            set
            {
                base.SetProperty<WeatherInfo>(ref this._WeatherInfos, value);
            }
        }

        /// <summary> 网络下行速度 </summary>
        public string NetDownSpeed
        {
            get { return _NetDownSpeed; }
            set
            {
                base.SetProperty<string>(ref this._NetDownSpeed, value);
            }
        }
        /// <summary> 网络上行速度 </summary>
        public string NetUpSpeed
        {
            get { return _NetUpSpeed; }
            set
            {
                base.SetProperty<string>(ref this._NetUpSpeed, value);
            }
        }

        #endregion

        #region 方法

        /// <summary>
        /// 初始化
        /// </summary>
        private void Loading()
        {
            #region 温馨提示

            string calendar = "农历：" + calender.ChineseDateString + "\r\n";
            calendar += " 时辰：" + calender.ChineseHour + "\r\n";
            calendar += " 属相：" + calender.AnimalString + "\r\n";
            calendar += (calender.ChineseTwentyFourDay.Length > 0) ? " 节气：" + calender.ChineseTwentyFourDay + "\r\n" : "";
            calendar += (calender.DateHoliday.Length > 0) ? " 节日：" + calender.DateHoliday + "\r\n" : "";
            calendar += " 星座：" + calender.Constellation + "\r\n";

            Helper.ShowPupUp("温馨提示！", null, calendar);
            #endregion

            this.Verson = "版本 V" + Helper.GetVersion();

            /*
            this._WeatherInfos = new WeatherInfo();
            this._WeatherInfos.Date = "06月10日 农历 五月初三";
            this._WeatherInfos.City = "北京";
            this._WeatherInfos.CurrWenDu = "31℃";
            this._WeatherInfos.Type = "多云";
            this._WeatherInfos.Image = Const.StartPath + "\\Weather\\big_rain.png";
            this._WeatherInfos.Summary = "各项气象条件适宜，发生感冒机率较低。但请避免长期处于空调房间中，以防感冒。";

            this._WeatherInfos.WeatherDays = new System.Collections.Generic.List<WeatherDay>();
            for (int i = 0; i < 5; i++)
            {
                this._WeatherInfos.WeatherDays.Add(new WeatherDay()
                {
                    Date = "今天（周五）",
                    Temperature = "18 ~ 31℃",
                    Image = Const.StartPath + "\\Weather\\big_rain.png",
                    Type = "多云",
                    WindInfo = "南风微风"
                });
            }
            */
            this._WeatherInfos = WeatherHelper.GetWeatherInfo(Const.CityName, Const.CityCode);

            //两小时获取一次
            ATimer.setInterval(2 * 60 * 3600, () =>
            {
                this._WeatherInfos = WeatherHelper.GetWeatherInfo(Const.CityName, Const.CityCode);
            });
        }
        #endregion
    }
}
